﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class UserControls_ucSearch : System.Web.UI.UserControl
{
    private int catMainID;

    public int CatMainID
    {
        get { return catMainID; }
        set { catMainID = value; }
    }

    private int catSubID;

    public int CatSubID
    {
        get { return catSubID; }
        set { catSubID = value; }
    }

    protected override void OnInit(EventArgs e)
    {
        //btnSearch.ServerClick += new EventHandler(btnSearch_ServerClick);
        base.OnInit(e);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            if (Request["action"] == "TÌM" || (Request["keyword"].Length > 0 && Request["keyword"] != "Tìm kiếm"))
            {
                string link = "listing.aspx";
                link += String.Format("?{0}={1}", FOConstants.QSP_MCID, CatMainID);
                link += String.Format("&{0}={1}", FOConstants.QSP_SCID, CatSubID);
                link += String.Format("&{0}={1}", FOConstants.QSP_FS, "");
                link += String.Format("&{0}={1}", FOConstants.QSP_FY, "");
                link += String.Format("&{0}={1}", FOConstants.QSP_SEARCH, Request["keyword"]);
                link += String.Format("&{0}={1}", FOConstants.QSP_CKID, SessionManager.GetCookie());
                Response.Redirect(link);
            }
        }
    }

    protected void btnSearch_ServerClick(object sender, EventArgs e)
    {
        string link = "listing.aspx";
        link += String.Format("?{0}={1}", FOConstants.QSP_MCID, CatMainID);
        link += String.Format("&{0}={1}", FOConstants.QSP_SCID, CatSubID);
        link += String.Format("&{0}={1}", FOConstants.QSP_FS, "");
        link += String.Format("&{0}={1}", FOConstants.QSP_FY, "");
        link += String.Format("&{0}={1}", FOConstants.QSP_SEARCH, Request["keyword"]);
        link += String.Format("&{0}={1}", FOConstants.QSP_CKID, SessionManager.GetCookie());
        Response.Redirect(link);
    }
}
